package com.config;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

/**
 * 登录验证拦截器
 */
public class AuthInterceptor extends HandlerInterceptorAdapter{

	/**
	 * 检测登录状态
	 */
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//		// 直接通过
//		String uri = request.getRequestURI();
//		if(uri.contains("login")) {
//			return true;
//		}
		// 登录验证成功通过
//		Object user = request.getSession().getAttribute("user");
//		if (Objects.nonNull(user)) {
			return true;
//		}
		// 其他情况一律拦截 (项目名 + 路径)
//		response.sendRedirect(request.getServletContext().getContextPath() + "/login");
//		return false;
	}

}
